# _*_ coding: UTF-8 _*_
# @Time     : 2021/11/15 13:34
# @Author   : yangshuaishuai
# @Site     : http://www.hzdledu.cn/
# @File     : prac1.py
# @Software : PyCharm

import unittest
from appium import webdriver
import time


class Test(unittest.TestCase):
    def setUp(self) -> None:
        # 手机设置
        desired_caps = {}
        desired_caps['platformName'] = 'Android'  # 系统名称
        desired_caps['platformVersion'] = '7.1.2'  # 系统的版本号
        desired_caps['deviceName'] = 'Android Emulator'  # 设备名称，这里是虚拟机，这个没有严格的规定
        desired_caps['appPackage'] = 'com.netease.cloudmusic'  # APP包名
        desired_caps['appActivity'] = 'com.netease.cloudmusic.activity.LoadingActivity'  # APP入口的activity
        desired_caps['noReset'] = True  # 不重置app的缓存文件
        desired_caps['unicodeKeyboard'] = True  # 设置键盘支持中文输入
        desired_caps['resetKeyboard'] = True  # 重置键盘

        # 连接appium server，告诉appium，代码要操作哪个设备上的哪个APP
        # 启动手机上App
        self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
        time.sleep(5)

    # def test1(self):  # 登录
    #     self.driver.find_element_by_id('com.netease.cloudmusic:id/l0').click()
    #     time.sleep(2)
    #     self.driver.tap([(310, 195)])
    #     time.sleep(2)
    #     self.driver.find_element_by_id('com.netease.cloudmusic:id/f8').click()
    #     time.sleep(1)
    #     self.driver.find_element_by_id('com.netease.cloudmusic:id/a69').click()
    #     time.sleep(1)
    #     self.driver.find_element_by_id('com.netease.cloudmusic:id/a69').send_keys('18705587625')
    #     time.sleep(1)
    #     self.driver.find_element_by_id('com.netease.cloudmusic:id/f7').click()
    #     time.sleep(1)
    #     self.driver.find_element_by_id('com.netease.cloudmusic:id/f7').send_keys('123456')
    #     time.sleep(1)
    #     self.driver.find_element_by_id('com.netease.cloudmusic:id/f8').click()
    #     time.sleep(3)
    #     self.driver.find_element_by_id('com.netease.cloudmusic:id/l0').click()
    #     time.sleep(1)
    #     self.driver.find_element_by_id('com.netease.cloudmusic:id/a25').click()
    #     time.sleep(1)
    #     self.driver.find_element_by_id('com.netease.cloudmusic:id/ajo').click()
    #     time.sleep(1)
    #     text = self.driver.find_element_by_id('com.netease.cloudmusic:id/a_d').text
    #     self.assertEqual("不想取名180220", text)
    #
    #     time.sleep(5)
    #
    # def test2(self):  # 搜索播放
    #     self.driver.find_element_by_accessibility_id('搜索').click()
    #     time.sleep(1)
    #     self.driver.find_element_by_id('com.netease.cloudmusic:id/search_src_text').click()
    #     time.sleep(1)
    #     self.driver.find_element_by_id('com.netease.cloudmusic:id/search_src_text').send_keys('张杰')
    #     time.sleep(1)
    #     self.driver.tap([(198, 227)])
    #     time.sleep(1)
    #     self.driver.tap([(93, 552)])
    #     time.sleep(1)
    #     self.driver.find_element_by_id('com.netease.cloudmusic:id/o8').click()
    #     time.sleep(1)
    #     text = self.driver.find_element_by_xpath(
    #         '//android.view.ViewGroup/android.widget.TextView[1]').text
    #     self.assertEqual("春天花会开", text)
    #     time.sleep(5)
    #
    #
    # def test3(self):  # 评价
    #     self.driver.tap([(445, 81)])
    #     time.sleep(1)
    #     self.driver.find_element_by_id('com.netease.cloudmusic:id/av8').click()
    #     time.sleep(3)
    #     self.driver.find_element_by_id('com.netease.cloudmusic:id/h2').send_keys('1')
    #     time.sleep(1)
    #     self.driver.find_element_by_id('com.netease.cloudmusic:id/a2a').click()
    #     time.sleep(2)
    #     text=self.driver.find_element_by_xpath('//android.widget.RelativeLayout[1]/android.widget.TextView[2]').text
    #     self.assertEqual("1",text)

    def test4(self):  # 电台操作
        self.driver.tap([(580, 144)])
        time.sleep(3)
        self.driver.find_element_by_id('com.netease.cloudmusic:id/a4o').click()
        time.sleep(1)
        self.driver.swipe(342, 1098, 342, 299)
        time.sleep(1)
        self.driver.swipe(342, 1098, 342, 299)
        time.sleep(1)
        self.driver.find_element_by_xpath('//android.widget.RelativeLayout[4]/android.widget.LinearLayout[1]').click()
        time.sleep(2)
        text = self.driver.find_element_by_xpath('//android.view.ViewGroup/android.widget.TextView[1]').text
        self.assertEqual("《追着幸福跑》郭德纲、于谦", text)
        time.sleep(5)

    def tearDown(self) -> None:
        self.driver.quit()
